
use "/homeKRTK/health_shocks/coworker_regfile_with_ncoworkers_AB_ModTreated_clean.dta", clear
capture drop _merge

merge m:1 vallazon_base using "/homeKRTK/health_shocks/coworkers_firms_exclude_AB.dta" //this is generated by the samples_comparison_AB_BM.do file in the event study folder
drop _m

gen EMP = 1 if FE_q_w!=.
	recode EMP (.=0) if FE_q_w==.
egen totEMP = total(EMP), by(anon)

gen stay2 = stay if EMP==1

foreach var of varlist EMP stay stay2 {
	gen pre`var' = `var' if relative_time<=7
	egen tot_pre`var' = total(pre`var'), by(anon)
}

drop if firms_exclude==1

***Coworker regressions, input for Figure 10 (saved in "$folder\coworker-data_July2025.xlsx") and Table 2

log using "/homeKRTK/health_shocks/EventStudy/coworker_JoLE_2025July_coworker_AB_ModTreated_clean.log", replace

estimates clear
areg w_q_w i.date i.relative_time rtdum2-rtdum16 if ev>=2012 & FE_q~=. & letszam~=. & tot_preEMP==8 & tot_prestay2>=1 & letszam_base<619 & match_sample==1, absorb(anon) rob
	est store all_bel619
		lincom -rtdum2-rtdum3-rtdum4-rtdum5-rtdum6-rtdum7-rtdum8

areg w_q_w i.date i.relative_time rtdum2-rtdum16 if ev>=2012 & FE_q~=. & letszam~=. & tot_preEMP==8 & tot_prestay2>=1 & letszam_base>=619 & letszam_base!=. & match_sample==1, absorb(anon) rob
	est store all_ab619
		lincom -rtdum2-rtdum3-rtdum4-rtdum5-rtdum6-rtdum7-rtdum8
		
areg w_q_w i.date i.relative_time rtdum2-rtdum16 if ev>=2012 & FE_q~=. & letszam~=. & tot_preEMP==8 & tot_prestay2>=1 & letszam_base<250 & match_sample==1, absorb(anon) rob
	est store all_bel250
		lincom -rtdum2-rtdum3-rtdum4-rtdum5-rtdum6-rtdum7-rtdum8

areg w_q_w i.date i.relative_time rtdum2-rtdum16 if ev>=2012 & FE_q~=. & letszam~=. & tot_preEMP==8 & tot_prestay2>=1 & letszam_base>=250 & letszam_base!=. & match_sample==1, absorb(anon) rob
	est store all_ab250
		lincom -rtdum2-rtdum3-rtdum4-rtdum5-rtdum6-rtdum7-rtdum8

areg w_q_w i.date i.relative_time rtdum2-rtdum16 if ev>=2012 & FE_q~=. & letszam~=. & tot_preEMP==8 & tot_prestay2>=4 & letszam_base<250 & match_sample==1, absorb(anon) rob
	est store switcher_bel250
		lincom -rtdum2-rtdum3-rtdum4-rtdum5-rtdum6-rtdum7-rtdum8

areg w_q_w i.date i.relative_time rtdum2-rtdum16 if ev>=2012 & FE_q~=. & letszam~=. & tot_preEMP==8 & tot_prestay2>=4 & letszam_base<619 & match_sample==1, absorb(anon) rob
	est store switcher_bel619
		lincom -rtdum2-rtdum3-rtdum4-rtdum5-rtdum6-rtdum7-rtdum8

areg w_q_w i.date i.relative_time rtdum2-rtdum16 if ev>=2012 & FE_q~=. & letszam~=. & tot_preEMP==8 & tot_prestay2>=4 & letszam_base<500 & match_sample==1, absorb(anon) rob
	est store switcher_bel500
		lincom -rtdum2-rtdum3-rtdum4-rtdum5-rtdum6-rtdum7-rtdum8
		
esttab *, cells(b(star fmt(5)) se(par([ ]) fmt(5)) t(par(( )) fmt(2))) legend starlevels(* 0.1 ** 0.05 *** 0.01) stats(r2 N, fmt(%9.3f %9.0g) labels(R^2))

xtset anon relative_time

capture drop after
gen after=0
replace after=1 if relative_time>=9 & relative_time<=12
replace after=2 if relative_time>=13 & relative_time<=16

estimates clear
xtreg w_q i.date treated##ib0.after if ev>=2012 & FE_q~=. & letszam~=. & tot_preEMP==8 & tot_prestay2>=4 & letszam_base<250 & match_sample==1, fe rob
	est  store est1
xtreg w_q i.date treated##ib0.after if ev>=2012 & FE_q~=. & letszam~=. & tot_preEMP==8 & tot_prestay2>=4 & letszam_base>=250 & letszam_base!=. & match_sample==1, fe rob
	est  store est2
xtreg w_q i.date treated##ib0.after if ev>=2012 & FE_q~=. & letszam~=. & tot_preEMP==8 & tot_prestay2>=4 & letszam_base<619 & match_sample==1, fe rob
	est  store est3
xtreg w_q i.date treated##ib0.after if ev>=2012 & FE_q~=. & letszam~=. & tot_preEMP==8 & tot_prestay2>=4 & letszam_base>=619 & letszam_base!=. & match_sample==1, fe rob
	est  store est4
xtreg w_q i.date treated##ib0.after if ev>=2012 & FE_q~=. & letszam~=. & tot_preEMP==8 & tot_prestay2>=4 & letszam_base<500 & match_sample==1, fe rob
	est  store est5
xtreg w_q i.date treated##ib0.after if ev>=2012 & FE_q~=. & letszam~=. & tot_preEMP==8 & tot_prestay2>=4 & letszam_base>=500 & letszam_base!=. & match_sample==1, fe rob
	est  store est6
esttab *, cells(b(star fmt(4)) se(par([ ]) fmt(4)) t(par(( )) fmt(2))) legend starlevels(* 0.1 ** 0.05 *** 0.01) stats(r2 N, fmt(%9.3f %9.0g) labels(R^2))

log close
